import { IsObject, IsString, Length, MaxLength, ValidateNested, IsUrl, IsOptional } from 'class-validator'
import { UserLinkTypes } from '../models/user.model'
import { Limits } from '@boticord/consts'
import { Type } from 'class-transformer'
import { IsOptionalString } from '@boticord/common/is-optional-string.decorator'
import { UpdateWebhookSettingsDto } from '@boticord/users-client/dto/update-webhook-settings.dto'

export class UserSocialsDto {
  @IsString()
  @MaxLength(Limits.MaxSocialLinkLength)
  @IsOptionalString()
  [UserLinkTypes.Vk]?: string

  @IsString()
  @MaxLength(Limits.MaxSocialLinkLength)
  @IsOptionalString()
  [UserLinkTypes.Telegram]?: string

  @IsString()
  @MaxLength(Limits.MaxSocialLinkLength)
  @IsOptionalString()
  @IsUrl({
    require_protocol: true,
    protocols: [ 'https', 'http' ],
  })
  [UserLinkTypes.Donate]?: string

  @IsString()
  @MaxLength(Limits.MaxSocialLinkLength)
  @IsOptionalString()
  @IsUrl({
    require_protocol: true,
    protocols: [ 'https', 'http' ],
  })
  [UserLinkTypes.Git]?: string

  @IsString()
  @MaxLength(Limits.MaxSocialLinkLength)
  @IsOptionalString()
  @IsUrl({
    require_protocol: true,
    protocols: [ 'https', 'http' ],
  })
  [UserLinkTypes.Custom]?: string
}

export class UpdateUserDto {
  @IsOptionalString()
  @IsString()
  @Length(Limits.MinUserDescriptionLength, Limits.MaxUserDescriptionLength)
  declare description?: string

  @IsOptionalString()
  @IsString()
  @Length(Limits.MinUserShortDescriptionLength, Limits.MaxUserShortDescriptionLength)
  declare shortDescription?: string

  @IsOptionalString()
  @IsString()
  @Length(Limits.MinShortLinkLength, Limits.MaxShortLinkLength)
  declare shortDomain?: string

  @IsObject()
  @ValidateNested()
  @Type(() => UserSocialsDto)
  declare socials: Record<UserLinkTypes, string>

  @IsOptional()
  @IsObject()
  @ValidateNested()
  @Type(() => UpdateWebhookSettingsDto)
  declare webhook?: UpdateWebhookSettingsDto
}
